package com.example.Controller;

import com.example.dao.RecordDao;
import com.example.pojo.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class AllController {
    @Autowired
    RecordDao recordDao;
    @RequestMapping("admin")
    public String show(Model model){
        List<Record> all = recordDao.findAll();
        model.addAttribute("emps",all);
        return "all";
    }
    @RequestMapping("/admin/find")
    public String find(@RequestParam("search") String search,
                       Model model){
        List<Record> records = recordDao.find(search);
        if (search.equals("")){
            List<Record> all = recordDao.findAll();
            model.addAttribute("emps",all);
            return "all";
        }
        else {
            model.addAttribute("emps", records);
            return "all";
        }
    }
}
